﻿<html>
<head>
<title>JavaScript插入排序</title>
</head>
<script>
	function binaryInsertionSort(array){
		for(var i=1;i<array.length;i++){
			var key=array[i],left=0,right=i-1;
			while(left<=right){
				var middle=parseInt((left+right)/2);
				if(key<array[middle]){
					right=middle-1;
				}else{
					left=middle+1;
				}
			}
			for(var j=i-1;j>=left;j--){
				array[j+1]=array[j];
			}
			array[left]=key;
			console.log(array.toString());
		}
		return array.toString();    
	}
	var array = [59,34,25,67,15,87,10,99,3,45]; 
	var res_arr = binaryInsertionSort(array);
	console.log("最终排序结果为："+res_arr.toString());
</script>
</html>